
public class Robot implements IQueryListenter {
	
//	public int interval = 1000;
	
	public Query[] querys = new Query[6];
	
	public Robot() {
		querys[0] = new GetPurchaseList();
		querys[1] = new GetChallengeList();
		querys[2] = new GetBattlePlayer();
		querys[3] = new ChallengeResult();		
		querys[4] = new GetChallengeRecord();
		querys[5] = new GetPVPRank();		
		//getBattlePlayer
		//getChallengeRecord
		//getPurchaseList
//		querys[2] = 
		for (int i = 0; i < querys.length; i++) {
			querys[i].listener = this;
		}
		querys[0].next = querys[1];
		querys[1].next = querys[2];
		querys[2].next = querys[3];
		querys[3].next = querys[4];
		querys[4].next = querys[5];
		querys[5].next = querys[0];
//		querys[1].next = querys[2];
//		querys[2].next = querys[3];
//		querys[3].next = querys[5];
	}

	@Override
	public void onComplete(Query q) {
		try {
			Thread.sleep(Config.interval);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		q.next.start();
	}
	
	public void sendRandomQuery() {
		int next = (int) Math.floor(Math.random() * 6); 
		querys[next].start();
	}
	
	public void start() {
		querys[0].start();
	}
	
	/**
	 * @param args
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws InterruptedException {
		if (args.length < 3) {
			System.out.println("no name");
			return;
		} else {
			int rid = Integer.parseInt(args[0]);
			Config.interval = Integer.parseInt(args[1]);
			Config.host = args[2];
			Config.name = "Robot" + String.format("%06d", rid);
		}
		
//		Config.name = "Robot000000";
//		Config.enemyName = "Robot000001";
		System.out.println("start robot with name:" + Config.name + ", interval:" + Config.interval + ", host:" + Config.host);
		new Robot().start();
//		while (true) {
//			Query.factory.releaseExternalResources();
//			Thread.sleep(1000);
//		}
	}
}
